package com.example.supernote.model.note.context

import android.net.Uri
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
import org.intellij.markdown.html.HtmlGenerator
import org.intellij.markdown.parser.MarkdownParser

class Context (
    var article: TextFieldValue = TextFieldValue(""),
    var selection: TextRange = TextRange(0, 0),
    var uri: Uri? = null,
    var name: String = "",
    var generateText: String = ""
) {
    fun parseContext(): String {
        val src = article.text
        val flavour = CommonMarkFlavourDescriptor()
        val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(src)
        val html = HtmlGenerator(src, parsedTree, flavour).generateHtml()
        return html
    }

    fun copy() =
        Context(
            article = this.article,
            selection = this.selection
        )
}